package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.common.model.Result;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 服务表 前端控制器
 * </p>
 *
 * @author itcast
 * @since 2023-07-03
 */
@Validated
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 服务相关接口")
public class ServeController {
    @Autowired
    private IServeService serveService;

    @ApiOperation("分页查询区域下的服务")
    @GetMapping("/page")
    public PageResult<ServeResDTO> findByPage(ServePageQueryReqDTO dto) {
        return serveService.findByPage(dto);
    }

    @ApiOperation("区域下城市新增服务")
    @PostMapping("/batch")
    public Result addServes(@RequestBody List<ServeUpsertReqDTO> dto) {
        return serveService.addServes(dto);
    }

    @ApiOperation("区域下城市服务价格修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "价格", required = true, dataTypeClass = BigDecimal.class)
    })
    @PutMapping("/{id}")
    public Result upServePrice(@PathVariable("id") Long id, BigDecimal price) {
        return serveService.upServePrice(id, price);
    }

    @DeleteMapping("/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public Result deleteById(@PathVariable("id") Long id) {
        return serveService.deleteById(id);
    }

    @PutMapping("/onSale/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public Result onServe(@PathVariable("id") Long id) {
        return serveService.onServe(id);
    }

    @PutMapping("/offSale/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public Result downServe(@PathVariable("id") Long id) {
        return serveService.downServe(id);
    }

    @PutMapping("/onHot/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public Result onHot(@PathVariable("id") Long id) {
        return serveService.onHot(id);
    }

    @PutMapping("/offHot/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
    })
    public Result offHot(@PathVariable("id") Long id) {
        return serveService.offHot(id);
    }
}
